package com.freelance.vn.apps.puzzle.utils;

import android.graphics.Bitmap;
import android.util.Log;
	 
public class ImageCropper {
	private final String LOG_TAG="ImageCropper";
	private int col=4;
	private int row = 6;//4x6
	private Bitmap originalBm=null;
	private int WIDTH=0;//width of bitmap child
	private int HEIGHT=0;//height of bitmap child
	public ImageCropper(Bitmap originalBm){
		this.originalBm=originalBm;
		init();
	}
	private void init(){
		if(originalBm!=null){
			int w=originalBm.getWidth();
			int h=originalBm.getHeight();
			WIDTH=w/col;
			HEIGHT=h/row;
			
			Log.i(LOG_TAG,"image root w: " + w + " h :" +h);
			Log.i(LOG_TAG,"image child w: " + WIDTH + " h :" +HEIGHT);
		}
	}
	
	public  Bitmap getBitmap(int x,int y){
		try{
		Bitmap result = Bitmap.createBitmap(originalBm, x*WIDTH, y*HEIGHT, WIDTH, HEIGHT);	
		return result;
		}catch(IllegalArgumentException e){
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
}
